package com.ymatou.iapi.optrade.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.parameter.req.OnXloboBillDeletedReq;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.optrade.service.OnXloboBillDeletedCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.utils.TestDataManager;

/**
 * 贝海通知面单已删除接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_OnXloboBillDeleted {

	private static OnXloboBillDeletedReq onXloboBillDeletedReq;
	private static OnXloboBillDeletedCall onXloboBillDeletedCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("贝海通知面单已删除接口");
	}

	@Before
	public void caseUp() {
		onXloboBillDeletedReq = new OnXloboBillDeletedReq();
		onXloboBillDeletedCall = new OnXloboBillDeletedCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(onXloboBillDeletedCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_OnXloboBillDeleted_001() {
		Logger.start(true, "同一订单下所有面单全部删除才能回滚订单");
		try {

			TradingServiceResp placeOrderResp = TradingCallService
					.orderDelivery();

			Long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			String billNo = "DB503225847US";

			TradingCallService.saveDeliverSummary(orderId, sellerId, billNo);

			onXloboBillDeletedReq.setBillNo(billNo);

			onXloboBillDeletedCall.setData(onXloboBillDeletedReq);

			onXloboBillDeletedCall.callService();

			Logger.verifyEquals("ok", onXloboBillDeletedCall.getReturnData(),
					"验证Code");

			Thread.sleep(3000);

			Ts_RollbackToWaitDelivery.verifyOrderStatus(orderId, "",
					"贝海面单被全部删除，已发货订单回滚至待发货");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_OnXloboBillDeleted_002() {
		Logger.start(true, "同一订单下有面单未全部删除");
		try {

			TradingServiceResp placeOrderResp = TradingCallService
					.orderDelivery();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			String billNo1 = String.format("YD%s",
					TestDataManager.getRandomNum(10));

			String billNo2 = String.format("YD%s",
					TestDataManager.getRandomNum(10));
			// 码头保存物流单号
			TradingCallService.saveDeliverSummary(orderId, sellerId, billNo1);
			TradingCallService.saveDeliverSummary(orderId, sellerId, billNo2);

			onXloboBillDeletedReq.setBillNo(billNo1);

			onXloboBillDeletedCall.setData(onXloboBillDeletedReq);

			onXloboBillDeletedCall.callService();

			Logger.verifyEquals("ok", onXloboBillDeletedCall.getReturnData(),
					"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}
